package com.maven.trans.demos.controller;


import com.maven.trans.demos.model.LogInfo;
import com.maven.trans.demos.service.LogService;
import com.maven.trans.demos.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/log")
@RestController
public class LogController {
    @Autowired
    UserService userService;
    @Autowired
    private LogService logService;

    //传播机制：REQUIRED级别： A，B共用一个 事务
    // 都成功：      事务 提交
    // 至少一个不成功：事务 回滚


    @Transactional(propagation = Propagation.REQUIRED)
    @RequestMapping("/l1")
    public String l1(String userName, String password) {
        userService.register(userName, password);
        LogInfo logInfo = new LogInfo();
        logInfo.setUserName(userName);
        logInfo.setOp("用户注册");
        logService.insert(logInfo);
        return "注册成功";
    }


}
